
#pragma once

#include "MyConfig.h"

using namespace Zen;
using namespace std;
using namespace Zen::Vap;

class LabelsLayer : public Layer2d
{
protected:
	// use native pointer....
	Zen::Vap::Label * m_fps_label = nullptr;
	Zen::Vap::Label * m_info_label = nullptr;

public:
	LabelsLayer()
	{
	}

	void load() override
	{
		this->loadFPSLabel();
		this->loadInfoLabel();
	}
	void setFPSText(std::string text)
	{
		m_fps_label->setText(text);
	}
	void loadFPSLabel()
	{
		auto label = std::make_shared<Label>();
		this->addNode(label);
		label->setFontBrush(gConfig.font_brush);
		label->setPosition(10, 0);
		label->setAnchor(0, 0);
		label->setCharsSpacingInPixels(2);
		label->setLinesSpacingInPixels(2);
		label->setText("i'm FPS");
//		label->setAlpha(0);
		label->setMaxWidthInPixels(0);
		label->setOrder(120);
		label->setTextAlignment(0.f);
		label->setUnderlineInPixels(2);
		label->setFontSize(50);

		m_fps_label = label.get();

	}
	void loadInfoLabel()
	{
		auto label = std::make_shared<Label>();
		this->addNode(label);

		label->setFontBrush(gConfig.font_brush);
		label->setPosition(10, gConfig.size.h);
		label->setAnchor(0, 1);
		label->setCharsSpacingInPixels(2);
		label->setLinesSpacingInPixels(2);
		label->setText("Hello! This is test\n123456789\n-=<>!!\nAlignment:center");
		label->setAlpha(0.8f);
		label->setMaxWidthInPixels(0);
		label->setOrder(120);
		label->setTextAlignment(0.5f);
		label->setUnderlineInPixels(2);
		label->setFontSize(50);
		label->setImageEffect(ImageEffectRainbow(0, -0.5f));

		/**
		 update label is a very waste of time. this is not a good solution.
		 */
#if 0
		label->runAction(ActionCall::Create([this, label](float interval) {
			effect_angel += interval * 2.f;
			label->setImageEffect(ImageEffectRainbow(effect_angel, effect_angel));

			cout << 1/interval << endl;

			return true;
		}, 0, 0, 1/10.f));
#endif

		m_info_label = label.get();
	}
	std::shared_ptr<Image> m_temp_image;
	float effect_angel = 0;
};
